﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BLL;
using Model;

public partial class Information_HelpMessageList : BasePage
{
    HelpMessageBO mbo = new HelpMessageBO();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (GetQeuryString("para") == "GetList")
        {
            BindData();
        }
        else if (GetQeuryString("para") == "delete")
        {
            try
            {
                Response.Clear();
                string id = GetQeuryString("id");
                HelpMessage m = mbo.GetModel(int.Parse(id));
                mbo.Delete(m.Id);
                Response.Write("ok");
            }
            catch (Exception ex)
            {
                Response.Write("Error" + ex.Message);
            }
            finally
            {
                Response.End();
            }

        }


    }

    private void BindData()
    {
        Response.Clear();
        //string s = "{\"total\":\"239\",\"rows\":[  {\"code\":\"001\",\"name\":\"Name 1\",\"addr\":\"Address 11\",\"addr\":\"col4 data\"}   ]}  ";
        int PageNumber = Convert.ToInt32(Request.Params["page"] == null ? "1" : Request.Params["page"]) - 1;
        int pageSize = Convert.ToInt32(Request.Params["rows"] == null ? "10" : Request.Params["rows"]);
        string sort = " order by " + (Request.Params["sort"] == null ? "id" : Request.Params["sort"]) + " " + (Request.Params["order"] == null ? " desc " : Request.Params["order"]);
        string condition = " 1=1 ";
        string uid = txtUID.Text;// Request.Params["txtUID"] == null ? "" : Request.Params["txtUID"];
        string username = txtUserName.Text;// Request.Params["UserName"] == null ? "" : Request.Params["UserName"];
        DataSet ds = access.GetAllHelpMessage(sort, pageSize, PageNumber, condition);
        string re = ToJson.DataTableToJson(ds.Tables[0].Rows[0][0].ToString(), "rows", ds.Tables[1]);
        Response.Write(re);
        Response.End();
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        BindData();
    }
}